package org.examplexx.mytestwebapplication.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.examplexx.mytestwebapplication.Mapper.EmpMapper;
import org.examplexx.mytestwebapplication.pojo.Emp;
import org.examplexx.mytestwebapplication.pojo.PageBean;
import org.examplexx.mytestwebapplication.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;


    @Override
    public void addEmp(Emp emp) {
        empMapper.insert(emp);
    }

    @Override
    public void deleteEmp(List<Integer> ids) {
        empMapper.delete(ids);
    }

    @Override
    public PageBean page(Integer page, Integer pagesize,String name,Integer gender, LocalDateTime entrytime, LocalDateTime endtime) {
        PageHelper.startPage(page, pagesize);
        List<Emp> empslist=empMapper.list(name, gender,  entrytime,  endtime);
        Page<Emp> p=(Page<Emp>) empslist;
        PageBean pb=new PageBean(p.getTotal(),p.getResult());
//        System.out.println("gender---"+gender);
        return pb;
    }
//    @Override
//    public PageBean page(Integer page, Integer pagesize) {
//        Long count= empMapper.count();
//        List<Emp> emps= empMapper.page((page-1)*pagesize,pagesize);
//        PageBean pageBean=new PageBean(count,emps);
//        return pageBean;
//    }
}
